package service

import (
	"context"

	commonTools "algo-sdk-go/common/tools"
	"algo-sdk-go/project/matchmaking/domain/models/entity"

	"github.com/globalsign/mgo/bson"
)

func (m *MatchMakingDomain) RecommendUser(ctx context.Context) ([]entity.UserProfile, error) {
	recommendUser, err := m.recommendUserRepo.LoadNearestRecommendUser(ctx)
	if err != nil {
		return nil, err
	}

	return m.userProfileRepo.LoadUserProfileByUserNums(ctx, recommendUser.RecommendUserIdList)
}

func (m *MatchMakingDomain) SetNearestRecommendUser(ctx context.Context, recommendUserIdList []int) error {
	if err := m.recommendUserRepo.Save(ctx, &entity.RecommendUser{
		Id:                  bson.NewObjectId().Hex(),
		RecommendUserIdList: recommendUserIdList,
		RecommendDate:       commonTools.TimeNow(),
	}); err != nil {
		return err
	}

	return nil
}
